package com.gdut.simple.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gdut.simple.R;
import com.gdut.simple.data.entity.User;
import com.gdut.simple.view.adapter.base.AbsRecyclerAdapter;
import com.gdut.simple.view.adapter.base.AbsViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.bmob.v3.datatype.BmobFile;
import de.hdodenhof.circleimageview.CircleImageView;

public class FollowAdapter extends AbsRecyclerAdapter<User> {

    public FollowAdapter(Context context, List<User> list) {
        super(context, list);
    }

    @Override
    protected AbsViewHolder createHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(mInflater.inflate(R.layout.layout_follow_item, parent, false));
    }

    @Override
    protected void showViewHolder(AbsViewHolder holder, int position) {
        final ItemViewHolder viewHolder = (ItemViewHolder) holder;
        BmobFile profile = mData.get(position).getProfile();
        if (profile == null) {
            viewHolder.profile.setImageResource(R.drawable.ic_load_error);
        } else {
            String profileUrl = profile.getUrl();
            Picasso.with(mContext)
                    .load(profileUrl)
                    .error(R.drawable.ic_load_error)
                    .into(viewHolder.profile);
        }
        viewHolder.name.setText(mData.get(position).getNickName());
    }

    private static class ItemViewHolder extends AbsViewHolder {

        CircleImageView profile;
        TextView name;

        ItemViewHolder(View itemView) {
            super(itemView);
            profile = (CircleImageView) itemView.findViewById(R.id.id_follow_user_profile);
            name = (TextView) itemView.findViewById(R.id.id_follow_user_name);
        }
    }

}
